package job

import (
	"git.supremind.info/product/box/vehicle/global"
	"git.supremind.info/product/box/vehicle/internal/kafka"
	"git.supremind.info/product/box/vehicle/internal/s3"
	"git.supremind.info/product/box/vehicle/internal/util"
	"git.supremind.info/product/box/vehicle/internal/vmr"
)

func SubscribeVmrPlatformCommandTopic() {
	for {
		var topicVO = vmr.VmrTopicVO{}
		//http://localhost:10066/v1/msg/group/:topic  是阻塞式的，不需要sleep
		url := global.VmrSetting.Host + "/v1/msg/group/__commands__/event-detect-box"
		err := util.Get(url, &topicVO)
		if err != nil {
			continue
		}
		kafkaBrokers := topicVO.Data.Body.Box.KafkaBrokers
		platformS3 := topicVO.Data.Body.Box.S3
		if kafkaBrokers == nil || len(kafkaBrokers) == 0 {
			kafka.GetInstance().DisConnectKafka()
			s3.PlatformInstance().DisAbleMinioClient()
		} else {
			kafka.GetInstance().ConnectKafka(kafkaBrokers)
			s3.PlatformInstance().InitMinioClient(platformS3)
		}
	}
}
